

import java.sql.*;
import java.util.Vector;

public class Test {
    public static void detect()throws ClassNotFoundException {

        Vector<String> campuri ;

       // initializare campuri

        campuri = new Vector<String>();
        campuri.add("firstName");
        campuri.add("lastName");
        campuri.add("tipSenzor");
        campuri.add("camera");


        try {
          //  Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/proiectcolectiv?" + "user=root&password=diana");
            Statement st = conn.createStatement();
            //st.executeUpdate("insert into senzor (firstName) values ('eu')");
            String sql = "select idsenzor from  senzor WHERE ";
            for (int i=0;i<campuri.size();i++){
                sql+=" ( ("+campuri.get(i)+" is NULL) or ("+campuri.get(i)+" LIKE '') )";

                if (i+1 < campuri.size()) sql+=" or ";
            }

            System.out.println(sql);

            ResultSet rs = st.executeQuery(sql);

           System.out.println("Senzorii urmatori nu au toate campurile completate:");
           while(rs.next()){
            System.out.println(rs.getInt("idsenzor"));
           }
           
          Statement stat = conn.createStatement();
           
          ResultSet rs1 = stat.executeQuery("select distinct idsenzor from valori");
           
           while (rs1.next()){
        	   
        	   int id = rs1.getInt("idsenzor");
        	   ResultSet rs2 = st.executeQuery("select idsenzor from senzor where idsenzor = "+id);
        	   if (!rs2.next()) System.out.println("Senzorul "+id+" nu exista in baza de date");
        	   
           }
           
           
        } catch (SQLException ex) {
            ex.printStackTrace();
            // Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
       public static void main (String args[]) throws ClassNotFoundException{

           detect();
       }
    

}

